//
//  ShareFriendViewController.m
//  DBAChain
//
//  Created by Evan on 2018/9/17.
//  Copyright © 2018 Evan. All rights reserved.
//

#import "ShareFriendViewController.h"
#import "taskHomePageService.h"
#import "SGQRCodeTool.h"

@interface ShareFriendViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *codeImage;
@property (weak, nonatomic) IBOutlet UIButton *button;
@property (weak, nonatomic) IBOutlet UILabel *lbIntCode;

@end

@implementation ShareFriendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"分享推广";
    [self initUI];
    [self loadData];
}

-(void)initUI{
    self.button.backgroundColor = COLOR_main;
    self.button.layer.masksToBounds = YES;
    self.button.layer.borderWidth = 1.0f;
    self.button.layer.borderColor = [UIColor clearColor].CGColor;
    self.button.layer.cornerRadius = 20.0f;
    self.lbIntCode.text = [UserCenter shareCenter].user.InvitationCode;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnClose:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)loadData{
    [DKProgressHUD showLoading];
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:@"1" forKey:@"isIos"];
    [taskHomePageService getVersion:dict success:^(dataVersion *response, BOOL success) {
        [DKProgressHUD dismiss];
        if (success) {
            self.codeImage.image = [SGQRCodeTool SG_generateWithDefaultQRCodeData:response.data.downloadurl imageViewWidth:204];
        }else{
            [DKProgressHUD showErrorWithStatus:response.message];
        }
    } failture:^(NSError *error, NSString *strDescription) {
        [DKProgressHUD dismiss];
        [DKProgressHUD showErrorWithStatus:strDescription];
    }];
}



- (IBAction)btnCopy:(id)sender {
    
    NSString *strUrl = [NSString stringWithFormat:@"%@home/register/%@",YBaseURLString,self.lbIntCode.text];
    
    
    UIPasteboard *Pasteboard = [UIPasteboard generalPasteboard];
    [Pasteboard setString:strUrl];
    if (Pasteboard == nil) {
        [DKProgressHUD showErrorWithStatus:@"复制失败"];
    }else{
        [DKProgressHUD showSuccessWithStatus:@"复制成功"];
    }
}


@end
